from flask.ext.wtf import CSRFProtect
from redis import StrictRedis
from flask import Flask,session
from flask_sqlalchemy import SQLAlchemy
from flask_session import Session
from flask_script import  Manager

class Config(object):
    """项目配置"""
    DEBUG = True

    SECRET_KEY = "iECgbYwASDASDASD1231134ASDASD"
    # 为数据库添加配置
    SQLAlchemy_DATABASE_URI = "mysql://root:mysql@127.0.0.1:3306/flask0999"
    SQLAlchemy_TRACK_MODIFICATIONS = False

    #Redis的配置
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    # Session 保存设置
    SESSION_TYPE = "redis"
    #开启session签名
    SESSION_SIGNER =True
    #指定Session 保存的redis
    SESSION_REDIS = StrictRedis(host=REDIS_HOST,port=REDIS_PORT)
    #设置需要过期
    SESSION_PERMANENT = False
    #设置过期时间
    PERMANENT_SESSION_LIFETIME = 86400 * 2
app = Flask(__name__)
#加载配置
app.config.from_object(Config)

#初始化数据库
db = SQLAlchemy(app)
#初始化redis 储存对象
redis_store = StrictRedis(host=Config.REDIS_HOST,port=Config.REDIS_PORT)
#开启当前项目 CSRF保护
CSRFProtect(app)
#设置session的保存指定位置
Session(app)

manager = Manager(app)

app.route("/")
def index():
    session["name"] = "itheima"
    return "index333"

if __name__ == '__main__':
    manager.run()
